package one.chapter_1;

import java.util.Random;

public class ThreeSum {

    public static void main(String []args){
        int a[] =new int [100];
        Random random=new Random();
        for (int i=0;i<100;i++){
            a[i]=random.nextInt(200)-100;
            System.out.println(a[i]);
        }



        Stopwatch stopwatch=new Stopwatch();
        int total=threeSum(a);
        System.out.println("total:"+total+"---执行时间:"+stopwatch.elapsedTime()+"s");


    }

    private static int threeSum(int[] a) {
        int total=0;
        for (int i=0;i<a.length;i++){ //n次
            for (int j=i+1;j<a.length;j++){
                for (int k=j+1;k<a.length;k++) {
                    if (a[i] + a[j]+a[k] == 0) {
                        total++;
                    }
                }
            }
        }

        return total;

    }


}
